package com.jetgege.loginmvp.model;


import android.os.Handler;
import android.text.TextUtils;

import com.jetgege.loginmvp.other.IOnLoginFinishedListener;
import com.jetgege.loginmvp.other.User;

/**
 * Created by Administrator on 2018/8/7.
 */

public class LoginModelImpl implements ILoginModel {
    @Override
    public void login(final String userName, final String password, final IOnLoginFinishedListener onLoginFinishedListener) {
        if (TextUtils.isEmpty(userName)){
            //用户名错误
            onLoginFinishedListener.onError("用户名不能为空！");
            return;
        }
        if (TextUtils.isEmpty(password)){
            //密码错误
            onLoginFinishedListener.onError("密码不能为空！");
            return;
        }
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (!userName.equals("admin")){
                    onLoginFinishedListener.onError("用户名错误！");
                }else if(!password.equals("123"))
                {
                    onLoginFinishedListener.onError("密码错误！");

                }else {
                    onLoginFinishedListener.onSuccess(new User(userName,password));
                }
            }
        },1500);
    }
}
